<?php
/**
 * Created by PhpStorm.
 * User: wangwangwang
 * Date: 5/6/25
 * Time: 9:29 AM
 */

namespace App\Controller;
use App\Model;
use Think\Controller;


class CatController extends BaseController
{
//得到所有分类
    public function getCatType()
    {
        $aPage = I('page', 1, 'intval');
        $aCount = I('count', 10, 'intval');
        $CatType = D('Cat/catEntity')->where(array('status' => 1))->page($aPage,$aCount)->select();
        foreach ($CatType as &$c) {
            $c['tpl2'] = op_t($c['tpl2']);
            $c['tpl1'] = op_t($c['tpl1']);
            $c['tpl3'] = op_t($c['tpl3']);
            $c['tpl_detail'] = op_t($c['tpl_detail']);
            $c['des3'] = op_t($c['des3']);
            $c['des2'] = op_t($c['des2']);
            $c['des1'] = op_t($c['des1']);
            $c['tpl_list'] = op_t($c['tpl_list']);
        }
        $list = array('list' => $CatType);

        $this->apiSuccess('返回成功', $list);
    }

//得到某一分类下的信息
    public function getCatList()
    {

        $aId = I('id', '', 'intval');

        $CatType = D('Cat/CatEntity')->where(array('status' => 1,'id'=>$aId))->find();

        if($CatType){
            $this->apiError('没有该分类');
        }
        $CatList = D('Cat/CatInfo')->where(array('status' => 1,'entity_id'=>$aId))->find();

        foreach ($CatList as &$c) {
            $c['title'] = op_t($c['title']);
            $c['create_time'] = friendlyDate($c['create_time']);
            $c['over_time'] = time_format($c['over_time']);
            $c['description'] = text($c['description']);
            $c['update_time'] = friendlyDate($c['update_time']);
            $c['data']=D('Cat/CatData')->where(array('status' => 1,'info_id'=>$c['id']))->select();

            foreach ($c['data'] as &$h) {
                $h['value']=op_t($h['value']);
            }
        }

        $list = array('list' => $CatList);
        $this->apiSuccess('返回成功', $list);
    }
    //得到某一分类下的信息
    public function getCatdetail()
    {

        $aId = I('id', '', 'intval');

        $CatType = D('Cat/CatEntity')->where(array('status' => 1,'id'=>$aId))->find();

        if($CatType){
            $this->apiError('没有该分类');
        }
        $CatList = D('Cat/CatInfo')->where(array('status' => 1,'entity_id'=>$aId))->find();

        foreach ($CatList as &$c) {
            $c['title'] = op_t($c['title']);
            $c['create_time'] = friendlyDate($c['create_time']);
            $c['over_time'] = time_format($c['over_time']);
            $c['description'] = text($c['description']);
            $c['update_time'] = friendlyDate($c['update_time']);
            $c['data']=D('Cat/CatData')->where(array('status' => 1,'info_id'=>$c['id']))->select();

            foreach ($c['data'] as &$h) {
                $h['value']=op_t($h['value']);
            }
        }

        $list = array('list' => $CatList);
        $this->apiSuccess('返回成功', $list);
    }
}